﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using System.Security.Principal;
using System.Web;
using System.Net;
using System.Threading;

namespace Deployment.TeamFoundation.Communication
{
    public class TeamServer : CommunicationBase
    {
        private static TeamServer instance;
        private static TeamFoundationServer _teamFoundationServer;

        protected TeamServer(){}

        #region Singleton
        
        public static TeamServer Instance
        {
            get
            {
                if (instance == null)
                {
                    Mutex mutex = new Mutex();
                    mutex.WaitOne();

                    if (instance == null)
                        instance = new TeamServer();

                    mutex.Close();
                }
                return instance;
            }
        }
        #endregion Singleton

        public TeamFoundationServer GetSinacorTeamServer()
        {
            if (_teamFoundationServer == null)
            {
                NetworkCredential cred = new System.Net.NetworkCredential();
                TeamFoundationServer tfs = new TeamFoundationServer(@"http://utilcorp05:8080");
                tfs.EnsureAuthenticated();
                _teamFoundationServer = tfs;
            }
            else
            {
                //"Obtendo o TeamFoundationServer. Usando Intância já criada"
            }
            return _teamFoundationServer;
        }
    }
}